package com.example.it.studymenu;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class OptionsActivity extends AppCompatActivity {

    private List<String> _dataSource;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_options);
        initData();
    }

    void initData() {
        _dataSource = new ArrayList<String>();
        for (int i = 0; i < 10; i++) {
            _dataSource.add("有关部门" + i);
        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // //拿到 menu的打气管
        // MenuInflater  mInflater = new MenuInflater(this);
        // //填充到 menu上
        // mInflater.inflate(R.menu.menu_mainactivity,menu);
        // return super.onCreateOptionsMenu(menu);

        initData();

        for (int i = 0; i < this._dataSource.size(); i++) {
            menu.add(1, i, i, _dataSource.get(i));
        }

        return super.onCreateOptionsMenu(menu);
    }

    //
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int index = item.getItemId();
        String value = _dataSource.get(index);
        Toast.makeText(this, value, Toast.LENGTH_SHORT).show();

        return super.onOptionsItemSelected(item);
    }
}
